package com.fisicaapp;



import android.annotation.SuppressLint;
import android.graphics.Canvas;

	@SuppressLint("WrongCall")
	public class animaPen  extends Thread {
		static final long FPS = 10;
		private PenduloView view;

	    private boolean running = false;   

	    public animaPen(PenduloView view) {
	          this.view = view;
	    }

	    public void setRunning(boolean run) {
	          running = run;
	    }

	    @Override

	    public void run() {
	        long ticksPS = 1000 / FPS;
	        long startTime;
	        long sleepTime;
	        
	          while (running) {
	                 Canvas c = null;
	                 startTime = System.currentTimeMillis();
	                 try {
	                        c = view.getHolder().lockCanvas();
	                        synchronized (view.getHolder()) { // evita que otros pinsas 
	                        view.onDraw(c);
	                        }
	                 } finally {
	                        if (c != null) {
	                               view.getHolder().unlockCanvasAndPost(c);
	                        }                        
	                 }
				sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
				try {
					if (sleepTime > 0)
						sleep(sleepTime);
					else
						sleep(20);
				} catch (Exception e) {
				}
	          }
	    }

		public void pintar() {
			// TODO Auto-generated method stub

	        Canvas c = null;
	        c = view.getHolder().lockCanvas();
	        view.onDraw(c);
	        view.getHolder().unlockCanvasAndPost(c);
			
		}
}

